package per.turtle.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import per.turtle.common.core.constant.CommonConstants;
import per.turtle.system.entity.SysOperLog;
import per.turtle.system.mapper.SysOperLogMapper;
import per.turtle.system.service.ISysOperLogService;

import java.util.List;

/**
 * 操作日志 服务层实现
 *
 * @author turtle
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService {

    @Override
    public void cleanOperLog() {
        baseMapper.cleanOperLog();
    }

    @Override
    public int deleteOperLogByIds(List<Long> operIds) {
        return baseMapper.deleteBatchIds(operIds);
    }

    @Override
    public int insertOperLog(SysOperLog operLog) {
        return baseMapper.insert(operLog);
    }

    @Override
    public SysOperLog selectOperLogById(Long operId) {
        return baseMapper.selectById(operId);
    }

    @Override
    public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>(operLog);
        wrapper.getEntity().setTitle(null);
        wrapper.lambda().like(StrUtil.isNotBlank(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle());
        wrapper.lambda().in(CollectionUtil.isNotEmpty(operLog.getBusinessTypes()), SysOperLog::getBusinessType, operLog.getBusinessTypes());
        wrapper.lambda()
               .le(operLog.getParams().get(CommonConstants.END_TIME) != null, SysOperLog::getOperTime, operLog.getParams().get(CommonConstants.END_TIME));
        wrapper.lambda()
               .ge(operLog.getParams().get(CommonConstants.START_TIME) != null, SysOperLog::getOperTime, operLog.getParams().get(CommonConstants.START_TIME));
        return baseMapper.selectList(wrapper);
    }

}
